import 'package:ccshop/entites/GoodsEntity.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HomeBottomListView extends StatefulWidget {
  @override
  _HomeBottomListViewState createState() => _HomeBottomListViewState();
}

class _HomeBottomListViewState extends State<HomeBottomListView> {
  List<GoodsEntity> goodsList = List();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    GoodsEntity goodsEntity = GoodsEntity(
      "images/test/test01.png",
      "波兰土豆进口【次日达】",
      "波兰原装进口 新鲜自然 醇香浓厚",
      "￥39.99",
      "￥45.00",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test02.png",
      "瑞士大白菜进口【今日达】",
      "波兰原装进口 清甜可口",
      "￥9.99",
      "￥25.00",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test03.png",
      "粉西红柿（番茄）500g/斤",
      "口味甘甜 圆润可口 皮薄肉多",
      "￥11.99",
      "￥35.00",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test04.png",
      "新鲜的猪肉 500g/斤",
      "每日新鲜 赶快来买",
      "￥25.99",
      "￥35.05",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test05.png",
      "刚出的竹笋",
      "大熊猫和人都喜欢吃的",
      "￥29.99",
      "￥45.15",
    );
    goodsList.add(goodsEntity);

    goodsEntity = GoodsEntity(
      "images/test/test06.png",
      "超新鲜蒜台 450g/斤",
      "甘甜可口 蒜台炒肉",
      "￥9.99",
      "￥18.99",
    );
    goodsList.add(goodsEntity);
  }

  @override
  Widget build(BuildContext context) {
    return SliverFixedExtentList(
      itemExtent: 150.0,
      delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
          return Column(
            children: [
              Divider(
                color: Color(0xFFE0E0E0),
                indent: 10,
              ),
              Container(
                margin: EdgeInsets.only(left: 10, right: 10, top: 16),
                child: Row(
                  children: [
                    Image.asset(
                      goodsList[index].goodsSrc,
                      width: 100,
                      height: 100,
                      fit: BoxFit.cover,
                    ),
                    Padding(padding: EdgeInsets.only(left: 10)),

                    // 右边布局
                    _HomeBottomRightView(goodsList[index]),
                  ],
                ),
              ),
            ],
          );
        },
        childCount: goodsList.length,
      ),
    );
  }
}

class _HomeBottomRightView extends StatelessWidget {

  final GoodsEntity goodsEntity;

  _HomeBottomRightView(this.goodsEntity);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text(
          goodsEntity.goodsName,
          style: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        ),
        Text(
          goodsEntity.goodsDesc,
          style: TextStyle(fontSize: 12, color: Colors.grey),
        ),
        Padding(padding: EdgeInsets.only(top: 14, bottom: 14)),

        Row(
          children: [
            Container(
              width: 180,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Text(
                    goodsEntity.goodsPrice,
                    style: TextStyle(
                      fontSize: 22,
                      color: Colors.red,),
                  ),
                  Text(
                    goodsEntity.goodsOldPrice,
                    style: TextStyle(
                        color: Colors.black,
                        decoration: TextDecoration.lineThrough),
                  ),
                ],
              ),
            ),
            Image.asset(
              "images/shop_item_cart.png",
              width: 26,
              height: 26,
            ),
          ],
        )
      ],
    );
  }
}
